package com.boot.security.server.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.boot.security.server.dto.appremkDto;
import com.boot.security.server.model.AppAccount;
import com.boot.security.server.model.AppRegsterMark;
import com.boot.security.server.utils.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.boot.security.server.page.table.PageTableRequest;
import com.boot.security.server.page.table.PageTableHandler;
import com.boot.security.server.page.table.PageTableResponse;
import com.boot.security.server.page.table.PageTableHandler.CountHandler;
import com.boot.security.server.page.table.PageTableHandler.ListHandler;
import com.boot.security.server.dao.AppZdDeptDao;
import com.boot.security.server.model.AppZdDept;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/appZdDepts")
public class AppZdDeptController {
    private static final Logger log = LoggerFactory.getLogger("adminLogger");

    @Autowired
    private AppZdDeptDao appZdDeptDao;

    @PostMapping
    @ApiOperation(value = "保存")
    public AppZdDept save(@RequestBody AppZdDept appZdDept) {
        appZdDeptDao.save(appZdDept);

        return appZdDept;
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id获取")
    public AppZdDept get(@PathVariable Long id) {
        return appZdDeptDao.getById(id);
    }

    @PutMapping
    @ApiOperation(value = "修改")
    public AppZdDept update(@RequestBody AppZdDept appZdDept) {
        appZdDeptDao.update(appZdDept);

        return appZdDept;
    }

    @GetMapping
    @ApiOperation(value = "列表")
    public PageTableResponse list(PageTableRequest request) {
        return new PageTableHandler(new CountHandler() {

            @Override
            public int count(PageTableRequest request) {
                return appZdDeptDao.count(request.getParams());
            }
        }, new ListHandler() {

            @Override
            public List<AppZdDept> list(PageTableRequest request) {
                return appZdDeptDao.list(request.getParams(), request.getOffset(), request.getLimit());
            }
        }).handle(request);
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除")
    public void delete(@PathVariable Long id) {
        appZdDeptDao.delete(id);
    }

    /**
     * 查询
     * @param appZdDept
     * 返回科室列表
     * @return R
     */
    @PostMapping("/find")
    public R findinfo(@RequestBody AppZdDept appZdDept){
//               List<AppZdDept>  appZdDeptList;
//               List<AppZdDept>  appZdDeptLists;
//               List<appremkDto> appremkDtoList = new ArrayList();
////        appRegsterMarkList= appRegsterMarkDao.getBylist(appRegsterMark.getHostcode(),appRegsterMark.getDeptcode(),appRegsterMark.getDoctorcode());
////        for (int i = 0; i < appRegsterMarkList.size(); i++) {
////            appremkDtoList=appRegsterMarkList;
////        }appRegsterMarkList
//         appremkDto appremkDtos=new appremkDto();
//        appZdDeptList=appZdDeptDao.getBylist("888888");
//        appZdDeptLists=appZdDeptList;
//        for (int i = 0; i < appZdDeptList.size(); i++) {
//            if(StringUtils.isEmpty(appZdDeptList.get(i).getPcode())){
//                log.info("信息-----------------------------------------1");
//                appremkDtos.setCode(appZdDeptList.get(i).getCode());
//                appremkDtos.setName(appZdDeptList.get(i).getName());
//                appremkDtoList.add(appremkDtos);
//            }
//
//       }
//        for (int i = 0; i < appremkDtoList.size(); i++) {
//            for (int k = 0; k < appZdDeptLists.size(); k++) {
//                if(!StringUtils.isEmpty(appZdDeptLists.get(k).getPcode())) {
//                    if (appremkDtoList.get(i).getCode()==appZdDeptLists.get(k).getPcode()){
//                        appremkDtoList.get(i).setAppZdDeptList(appZdDeptLists);
//                    }
//                }
//            }
//
//        }




     //   return new R<>(appremkDtoList);
        return new R<>( appZdDeptDao.getBylist("888888"));
        //    return new R<>(  bxbFbqksDao.getById(bxbFbqks.getId()));
    }

}
